﻿using System.Collections.Generic;
using System.Linq;
using DataBaseLayer.Dto;

namespace DataBaseLayer.Extensions
{
	public static class NewsEx
	{
		public static NewsData ToDTO(this News entity)
		{
			if (entity == null) return null;

			var dto = new NewsData
			{
				NewsId = entity.NewsId,
				Header = entity.Header,
				Description = entity.Description,
				GalleryId = entity.GalleryId,
				IsNewsForFotoClubImages = entity.Gallery != null && entity.Gallery.IsFotoclub,
				IsNewsForGalleryImages = entity.Gallery != null && entity.Gallery.IsImagesGallery
			};

			return dto;
		}

		public static List<NewsData> ToDTOs(this IEnumerable<News> entities)
		{
			if (entities == null) return null;

			return entities.Select(e => e.ToDTO()).ToList();
		}
	}
}
